package samsung.sds.systemMonitor.userOperationMonitor.service.impl;

import java.net.UnknownHostException;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import samsung.sds.system.common.baseQuery.AbstractBaseService;
import samsung.sds.system.common.baseQuery.BaseMapper;
import samsung.sds.systemMonitor.userOperationMonitor.dao.UserOperationMonitorMapper;
import samsung.sds.systemMonitor.userOperationMonitor.model.MonitorOperationEntity;
import samsung.sds.systemMonitor.userOperationMonitor.model.MonitorUserBaseInfo;
import samsung.sds.systemMonitor.userOperationMonitor.service.UserOperationMonitorService;
import samsung.sds.systemMonitor.userOperationMonitor.utils.Constants;

/**
 * 用户操作监控service
 * 
 * @author lixin.qiu
 * @createDate 2016-01-18
 * 
 */
@Service
public class UserOperationMonitorServiceImpl extends
		AbstractBaseService<MonitorOperationEntity> implements
		UserOperationMonitorService {

	@Autowired
	private UserOperationMonitorMapper userOperationMonitorMapper;

	@Override
	protected BaseMapper<MonitorOperationEntity> getMapper() {
		return userOperationMonitorMapper;
	}

	/**
	 * 插入攻击者的信息
	 * 
	 * @param request
	 * @param userName
	 * @param moduleName
	 * @return
	 */
	@Override
	public int insertAttackOperationInfo(HttpServletRequest request,
			String userName, String moduleName) throws UnknownHostException {
		MonitorOperationEntity monitorOperationEntity = MonitorUserBaseInfo
				.getMonitorOperationInfo(request);
		monitorOperationEntity.setCreateUser(userName);
		monitorOperationEntity.setOpType(Constants.ATTACK);
		monitorOperationEntity.setModuleName(moduleName);
		return userOperationMonitorMapper.insertEntity(monitorOperationEntity);
	}
	
	@Override
	public int insertEntity(MonitorOperationEntity monitorOperationEntity){
		return userOperationMonitorMapper.insertEntity(monitorOperationEntity);
	}

}
